package uk.co.q3c.deplan.client.util;

import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;

import uk.co.q3c.deplan.client.domain.task.BaseTask;

@Test
public class Q3StringUtil_UT {
	transient protected final Logger logger = Logger.getLogger(getClass().getName());

	public void stringCompare() {
		Assert.assertEquals(Q3StringUtil.compare("x", "y"), -1);
		Assert.assertEquals(Q3StringUtil.compare("y", "x"), 1);
		Assert.assertEquals(Q3StringUtil.compare("xx", "y"), -1);
		Assert.assertEquals(Q3StringUtil.compare("x", "x"), 0);
		Assert.assertEquals(Q3StringUtil.compare("xx", "xxx"), -1);
		Assert.assertEquals(Q3StringUtil.compare(null, "xxx"), -1);
		Assert.assertEquals(Q3StringUtil.compare("x", null), 1);
		Assert.assertEquals(Q3StringUtil.compare(null, null), 0);
	}

	public void splitAtCamelCase() {
		Assert.assertEquals(Q3StringUtil.splitAtCamelCase("camelCase"), "camel case");
		Assert.assertEquals(Q3StringUtil.splitAtCamelCase("camelcase"), "camelcase");
		Assert.assertEquals(Q3StringUtil.splitAtCamelCase("Camelcase"), "Camelcase");
		Assert.assertEquals(Q3StringUtil.splitAtCamelCase("CamelCase"), "Camel case");
	}

	public void simpleName() {
		Assert.assertEquals(Q3StringUtil.simpleNameFromClassName(BaseTask.class.getName()), "BaseTask");
	}

	public void methodNameFromFieldName() {
		String s = Q3StringUtil.methodNamefromfieldName("has", "onions");
		Assert.assertEquals(s, "hasOnions");
	}

	public void instanceNameFromClassName() {
		String s = Q3StringUtil.instanceNameFromClass("BigOnion");
		Assert.assertEquals(s, "bigOnion");
	}
}
